import java.util.Arrays;
import java.util.Scanner;

public class Comparable_pta451 {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PersonSortable[] str=new PersonSortable[in.nextInt()];
		for (int i = 0; i < str.length; i++) {
			str[i]=new PersonSortable(in.next(), in.nextInt());
		}
		Arrays.sort(str);
		for (int i = 0; i < str.length; i++) {
			System.out.println(str[i]);
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
		in.close();
	}
}
class PersonSortable implements Comparable<PersonSortable> {
	private String name;
	private int age;
	public PersonSortable(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}
	@Override
	public String toString() {
		return String.format("%s-%d", name,age);
	}
	@Override
	public int compareTo(PersonSortable o) {
		if(this.name.compareTo(o.name)!=0){
			return this.name.compareTo(o.name);
		}
		else{
			return Integer.toString(this.age).compareTo(Integer.toString(o.age));
		}
		
	}
}
